<template>
	<view>
		<view class="mainView">
			<image class="image" :src="imageSrc" mode="widthFix"></image>
			<!-- 分页栏 活动 -->
			<view class="tabView">
				<view :class="nowTab==0?'actTab':'norTab'" @click="onClickTab(0)">排行榜</view>
				<view :class="nowTab==1?'actTab':'norTab'" @click="onClickTab(1)">我的</view>
			</view>
			<!-- 分页栏 固定 -->
			<view v-if="showFlexTab" class="tabViewFlex" >
				<view :class="nowTab==0?'actTab':'norTab'" @click="onClickTab(0)">排行榜</view>
				<view :class="nowTab==1?'actTab':'norTab'" @click="onClickTab(1)">我的</view>
			</view>
			<!-- 标签页1 -->
			<view class="tabOne" v-show="nowTab==0">
				<myRow rank="排名" nickName="昵称" score="积分"></myRow>
				<view class="myRow" :wx:for="list" wx:key="rank">
					<myRow :rank="item.rank" :nickName="item.nickName" :score="item.score"></myRow>
				</view>
			</view>
			<!-- 标签页2 -->
			<view class="tabTwo" v-show="nowTab==1">
				<view class="scoreLabel">我的得分: {{me.score}}积分<view class="scoreRecord" @click="onClickScoreRecord">积分明细</view></view>
				<view class="scoreLabel">我的排名: {{me.rank}}/{{sum}}</view>
				综合得分
				<progress :percent="percentScore" stroke-width=10 active show-info></progress>
			</view>
		</view>
		<view class="safeView"></view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				nowTab:0,
				showFlexTab:false,
				imageSrc:this.myConfig.storageUrl+'/static/rankImage.jpg',
				sum:1,
				percentScore:0,
				list:[],
				me:{}
			}
		},
		onLoad(){
			const that=this;
			wx.showLoading({
			  title:'loading...',
			  mask:true
			});
			wx.request({
				url:that.myConfig.hostUrl+'/api/rank.php',
				method:'POST',
				data:{
					openId:that.myConfig.openId
				},
				success:function(res){
					console.log('rank',res);
					if(res.data.errCode==200){
						setTimeout(function(){
							wx.hideLoading();
							that.list=res.data.list;
							that.me=res.data.me;
							that.sum=res.data.sum;
							if(that.me.rank==1)
								that.percentScore=100;
							else
								that.percentScore=parseInt((that.sum-that.me.rank)*100/that.sum);
						},200);
					}else{
						wx.hideLoading();
						wx.showToast({
							title:'网络好像不太好',
							icon:'none',
							duration:1200
						});
					}
				},
				fail:function(){
					wx.hideLoading();
					wx.showToast({
						title:'网络好像不太好',
						icon:'none',
						duration:1200
					});
				}
			});
		},
		onPageScroll(now){
			const that=this;
			if(now.scrollTop>=300){
				that.showFlexTab=true;
			}else
				that.showFlexTab=false;
		},
		methods:{
			onClickTab(act){
				const that=this;
				if(that.nowTab==act)
					return ;
				that.nowTab^=1;
			},
			onClickScoreRecord(){
				uni.navigateTo({
					url:'/pages/scoreRecord/scoreRecord'
				});
			}
		}
	}
</script>

<style scoped>
	.image{
		width: 100%;
	}
	.mainView{
		width: 100%;
	}
	.tabView{
		width: 100%;
		height: 100rpx;
		display: flex;
		background-color: #ffffff;
		justify-content: space-around;
		align-items: center;
	}
	.tabViewFlex{
		width: 100%;
		height: 100rpx;
		display: flex;
		background-color: #ffffff;
		justify-content: space-around;
		align-items: center;
		position: fixed;
		top: 0;
	}
	.actTab{
		height: 80%;
		width: 50%;
		font-weight: 800;
		color: #b2d1ff;
		display: flex;
		justify-content: center;
		align-items: center;
		border-bottom:10rpx solid #b2d1ff;
	}
	.norTab{
		height: 80%;
		width: 50%;
		font-weight: 800;
		color: #555555;
		display: flex;
		justify-content: center;
		align-items: center;
		border-bottom:10rpx solid #ffffff;
	}
	.tabOne{
		margin: 25rpx;
	}
	.tabTwo{
		margin: 25rpx;
		font-weight: 600;
	}
	.myRow{
		margin-top: 10rpx;
	}
	.scoreLabel{
		display: flex;
		align-items: center;
		font-size: 40rpx;
		color: #B2e088;
		margin: 15rpx 0;
	}
	.scoreRecord{
		margin-left: 15rpx;
		color: #B2d1FF;
		font-size: 30rpx;
	}
</style>
